package com.example.demothree.service.imp;

import com.example.demothree.bean.Customer;
import com.example.demothree.bean.Goods;
import com.example.demothree.bean.Suppliers;
import com.example.demothree.dao.SuppliersDao;
import com.example.demothree.dao.CustomerDao;
import com.example.demothree.dao.GoodsDao;
import com.example.demothree.service.SysService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysServiceImp implements SysService {
    @Resource
    private GoodsDao goodsDao;
    @Resource
    private SuppliersDao suppliersDao;
    @Resource
    private CustomerDao customerDao;
    @Override
    public Page<Goods> sysSpzl(Integer page, Integer size) {
        Pageable pageable = PageRequest.of(page,size);
        Page<Goods> pagespzl = goodsDao.findAll(pageable);
        return pagespzl;
    }
    //供应商分页
    @Override
    public Page<Suppliers> sysGyszl(Integer page, Integer size) {
        Pageable pageable = PageRequest.of(page,size);
        Page<Suppliers> pagegyszl = suppliersDao.findAll(pageable);
        return pagegyszl;
    }
    //删除供应商
    @Override
    public void deletegyszl(Long id) {
        suppliersDao.deleteById(id);
    }
    //添加供应商
    @Override
    public Suppliers addgys(Suppliers suppliers) {
        return suppliersDao.save(suppliers);
    }
    //name查询供应商
    public Suppliers findgysByName(String name) {
        return suppliersDao.findSuppliersByName(name);
    }
    //客户分页
    @Override
    public Page<Customer> sysKhzl(Integer page, Integer size) {
        Pageable pageable = PageRequest.of(page,size);
        Page<Customer> pagekhzl = customerDao.findAll(pageable);
        return pagekhzl;
    }
    //删除客户
    @Override
    public void deletekhzl(Long id) {
        customerDao.deleteById(id);
    }
    //添加客户
    @Override
    public Customer addkh(Customer customer) {
        return customerDao.save(customer);
    }

}
